import os

from selenium import webdriver
import time

from selenium.webdriver.common.by import By



class Mailbox:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://email.163.com/')
        #定义一个登录类
    def sign(self):
        frame = self.driver.find_element(By.XPATH, '//*[contains(@id,"x-URS-iframe")]') #定位iframe
        print(frame.get_attribute("outerHTML")) #打印定位的源代码
        self.driver.switch_to.frame(frame) #切换到指定的iframe
        #定位账号输入类容
        self.driver.find_element(By.XPATH, "//input[@name='email' and @data_存放测试数据-type='email']").send_keys('abc1194971161')
       # 定位密码输入内容
        self.driver.find_element(By.XPATH, "//input[@data_存放测试数据-placeholder='输入密码']").send_keys('aA123889')
        #定位登录按钮,点击
        self.driver.find_element(By.ID, 'dologin').click()

    #定义一个发送类
    def fasong(self):

        time.sleep(3)
        self.driver.find_element(By.ID, '_mail_component_149_149').click() #定位写信按钮点击
        #定位收件人写入类容
        self.driver.find_element(By.CLASS_NAME, "nui-editableAddr-ipt").send_keys('1228017824@qq.com')
        #定位到主题写入类容
        self.driver.find_element(By.XPATH, "//*[contains(@id,'subjectInput')]").send_keys('作业')
        time.sleep(3)
        frame = self.driver.find_element(By.CLASS_NAME, 'APP-editor-iframe') #定位iframe
        print(frame.get_attribute('outerHTML'))
        self.driver.switch_to.frame(frame)  #切换到iframe
        self.driver.find_element(By.CLASS_NAME, 'nui-scroll').send_keys('python关机既开启') #定位文本框写入类容
        self.driver.switch_to.default_content()  #切换到主页面
        self.driver.find_element(By.XPATH, "//footer[@class='jp0']/div[1]/span[2]").click() #定位发送按钮并点击
    def text1(self):
        time.sleep(3)
        self.driver.find_element(By.ID, '_mail_component_149_149').click()  # 定位发送邮件按钮点击
        file1 =print(os.path.dirname(os.path.abspath(__file__)) + '/cookie操作.py')
        self.driver.find_element(By.XPATH, "//input[@type='file']").send_keys(file1)



    def quit(self):
        time.sleep(2)
        self.driver.quit()

if __name__ == '__main__':
    mailbox = Mailbox()
    mailbox.sign()
    mailbox.text1()
    # mailbox.fasong()
    # mailbox.quit()




    #















